package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @create: 2024/9/11
 * @author: gyhe10
 * @description:
 **/

@RestController
public class MqController {

    @Resource
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/send")
    public String sendMessage(@RequestParam(value = "count") Integer count) {
        for (int i = 0; i < count; i++) {
            OrderReturnReasonEntity returnReason = new OrderReturnReasonEntity();
            returnReason.setId(Long.valueOf(count));
            returnReason.setName("哈哈哈" + i);
            rabbitTemplate.convertAndSend("hello-java-exchange", "hello.java", returnReason, new CorrelationData(UUID.randomUUID().toString()));
        }
        return "ok";
    }
}
